package com.ukao.cashregister.pesenter;
import com.ukao.cashregister.base.BasePresenter;
import com.ukao.cashregister.bean.AddClothingItem;
import com.ukao.cashregister.consts.Constant;
import com.ukao.cashregister.retrofit.ApiCallback;
import com.ukao.cashregister.view.AddClothingView;

import java.util.HashMap;

import rx.Observable;

/**
 * Created by ukaodev on 2017/6/26.
 */

public class AddClothingPesenter extends BasePresenter<AddClothingView> {
    public static final int  BRAND=7;  //品牌
    public static final int FLAW=5;
    public static final int COLOR=4;//颜色
    public static final int AFTER_WASHING_EFFECT=6;
    public static final int  PROJECT=0;
    public static final int  SERVICE=2;
    public static final int  ANNEX=3;
    public static  final int ATTACH=8;
    private boolean isShowLoad=true;

    public AddClothingPesenter(AddClothingView view) {
        attachView(view);
    }






    /**
     *项目       productId
     */
    public void projectData(HashMap  mHashMap) {
            mvpView.showLoading();
        Observable observable = null;
                observable=apiStores.project(Constant.createParameter(mHashMap));
        addSubscription(observable,
                new ApiCallback<AddClothingItem>() {
                    @Override
                    public void onSuccess(AddClothingItem model) {
                        if (model.getHttpCode()==200){
                            mvpView.getProjectSuccess(model.getData());
                        }else{
                            mvpView.loadFail(model.getMsg());
                        }
                    }

                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();
                    }

                });
    }

    /**
     * 产品附加服务
     * @param mHashMap
     */
    public void productAddService(HashMap mHashMap ) {
            mvpView.showLoading();
        addSubscription(apiStores.productAddService(Constant.createParameter(mHashMap)),
                new ApiCallback<AddClothingItem>() {
                    @Override
                    public void onSuccess(AddClothingItem model) {
                        if (model.getHttpCode()==200){
                            mvpView.getProjectSuccess(model.getData());
                        }else{
                            mvpView.loadFail(model.getMsg());
                        }
                    }
                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();
                    }
                });
    }
    /**
     * 请求品牌
     * @param mHashMap
     */
    public  void  productBrand(HashMap mHashMap,boolean isSearch){
        if(isShowLoad){
            mvpView.showLoading();
        }
//        Log.i("cj",new Gson().toJson(mHashMap));
        addSubscription(apiStores.productBrand(Constant.createParameter(mHashMap)),
                new ApiCallback<AddClothingItem>() {
                    @Override
                    public void onSuccess(AddClothingItem model) {
                        if (model.getHttpCode()==200){
                            if(!isSearch)
                                mvpView.getProjectSuccess(model.getData());
                            else
                                mvpView.getSearchDataSuccess(model.getData());
                        }else{
                            mvpView.loadFail(model.getMsg());
                        }
                    }
                    @Override
                    public void onFinish() {
                        if(isShowLoad){
                            mvpView.hideLoading();
                            isShowLoad=false;
                        }else {
                            mvpView.finishLoadMore();
                        }
                    }

                });
    }
    /**
     * 请求洗后效果数据
     */
    public  void productAfterWashingEffect(HashMap mHashMap,boolean isSearch){
        if(isShowLoad){
            mvpView.showLoading();
        }
        addSubscription(apiStores.productEffect(Constant.createParameter(mHashMap)),
                new ApiCallback<AddClothingItem>() {
                    @Override
                    public void onSuccess(AddClothingItem model) {
                        if (model.getHttpCode()==200){
                            if(!isSearch)
                                mvpView.getProjectSuccess(model.getData());
                            else
                                mvpView.getSearchDataSuccess(model.getData());
                        }else{
                            mvpView.loadFail(model.getMsg());
                        }
                    }
                    @Override
                    public void onFinish() {
                        if(isShowLoad){
                            mvpView.hideLoading();
                            isShowLoad=false;
                        }else {
                            mvpView.finishLoadMore();
                        }
                    }

                });
    }
    /**
     * 请求瑕疵
     * @param mHashMap
     */
    public void  productFlaws(HashMap mHashMap,boolean isSearch){
        if(isShowLoad){
            mvpView.showLoading();
        }
        addSubscription(apiStores.productFlaw(Constant.createParameter(mHashMap)),
                new ApiCallback<AddClothingItem>() {
                    @Override
                    public void onSuccess(AddClothingItem model) {
                        if (model.getHttpCode()==200){
                            if(!isSearch)
                                mvpView.getProjectSuccess(model.getData());
                            else
                                mvpView.getSearchDataSuccess(model.getData());
                        }else{
                            mvpView.loadFail(model.getMsg());
                        }
                    }
                    @Override
                    public void onFinish() {
                        if(isShowLoad){
                            mvpView.hideLoading();
                            isShowLoad=false;
                        }else {
                            mvpView.finishLoadMore();
                        }
                    }

                });
    }
    /**
     * 请求颜色
     * @param mHashMap
     */
    public  void  productColors(HashMap mHashMap,boolean isSearch){
        if(isShowLoad){
            mvpView.showLoading();
        }
        addSubscription(apiStores.productColor(Constant.createParameter(mHashMap)),
                new ApiCallback<AddClothingItem>() {
                    @Override
                    public void onSuccess(AddClothingItem model) {
                        if (model.getHttpCode()==200){
                            if(!isSearch)
                                 mvpView.getProjectSuccess(model.getData());
                            else
                                mvpView.getSearchDataSuccess(model.getData());
                        }else{
                            mvpView.loadFail(model.getMsg());
                        }
                    }
                    @Override
                    public void onFinish() {
                        if(isShowLoad){
                            mvpView.hideLoading();
                            isShowLoad=false;
                        }else {
                            mvpView.finishLoadMore();
                        }
                    }
                });
    }

    /**
     * 请求附件
     * @param mHashMap
     */
    public void productAnnex(HashMap mHashMap) {
            mvpView.showLoading();
        addSubscription(apiStores.productAnnex(Constant.createParameter(mHashMap)),
                new ApiCallback<AddClothingItem>() {
                    @Override
                    public void onSuccess(AddClothingItem model) {
                        if (model.getHttpCode()==200){
                            mvpView.getProjectSuccess(model.getData());
                        }else{
                            mvpView.loadFail(model.getMsg());
                        }
                    }
                    @Override
                    public void onFinish() {
                            mvpView.hideLoading();
                    }
                });
    }
    /**
     *  产品服务
     * @param mHashMap
     */
    public void productService(HashMap mHashMap ) {

            mvpView.showLoading();

        addSubscription(apiStores.productService(Constant.createParameter(mHashMap)),
                new ApiCallback<AddClothingItem>() {
                    @Override
                    public void onSuccess(AddClothingItem model) {
                        if (model.getHttpCode()==200){
                            mvpView.getProjectSuccess(model.getData());
                        }else{
                            mvpView.loadFail(model.getMsg());
                        }
                    }

                    @Override
                    public void onFinish() {
                            mvpView.hideLoading();
                    }

                });
    }






}
